<!--#include file="../nav/admin_top.php" -->
<style type="text/css">

.tables{
border-collapse:collapse;
color:#555555;
}
.tables th{
background-color:#FFFFCC;
}
.tables td,.tables th{
padding:5px;
vertical-align:top;
text-align:center;
border:1px solid #CCCCCC;
}

tr.on td{
background-color:#F3FDE3;
}
.opts a{
margin-left:10px;
}
.opts a:hover{
background-color:transparent!important;
color:#336699!important;
}

.indexs{
color:#FF3300;
font-size:1.2em;
font-weight:bold;
}

.mybtn {
background-color:#DDDDDD;
border:1px solid #AAAAAA;
color:#224466;
cursor:pointer;
margin-left:10px;
padding:1px 3px;
}
</style>  
<script type="text/javascript"> 
var url_del = '/admin_wrapper/deltype';
var url_modify = '/admin_wrapper/mdifytype';


var nums={count($rs)};
$().ready(function(){
	showLoading();
	o2js.build('json');
	fnShowIndex(); 
	
	$('#add_name').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnAdd();
		}
	}).focus(); 
});
/* 上移动 */
function fnToUp(id){
	var curteam = '#mytype_'+id;
	if($(curteam).prev().length == 0) return false;
	$(curteam).prev().before( $(curteam) );
	//$(curteam).effect("highlight");
	fnShowIndex();
}
/* 下移动 */
function fnToDown(id){
	var curteam = '#mytype_'+id;
	if($(curteam).next().length == 0) return false;
	$(curteam).next().after( $(curteam) );
 
	//$(curteam).effect("highlight");
	fnShowIndex();
}
/* 排序管理 */
function fnShowIndex(){
	var i=1;
	$('#mytypes tr').each(function(e){
		var tmp = i++;
		$(this).find('.indexs').html(tmp);
	});
}
/* 添加 */
function fnAdd(){
	var add_name = $.trim( $('#add_name').val() );
	if(add_name == ''){
		alert('请先选择图片【菜品种类名称】');
	  $('#add_name').focus();
		return false;
	}
	 
}
/* 删除 */
function fnDel(id){
	fnConfirm({
		str:'删除本行数据?',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_del,
				{
					id:$('#id_'+id).val()
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						$('#mytype_'+id).remove();
						fnShowIndex();
					}
					$('button').attr('disabled','');
				}
			);
		}
	}); 
} 
/* 保存 */
function fnSave(){
	var objs = []; 
	for(var i=0; i<nums; i++){
		if(fnDom('mytype_'+i)){ 
			var tmp  ={};
			tmp['show_index'] = $('#mytype_'+i+' .indexs').html();
			tmp['id'] = $.trim($('#id_'+i ).val());
			objs.push(tmp); 
		}
	}
	if(objs.length == 0){
		alert('没有任何可保存数据！');
		return false;
	} 
	$('button').attr('disabled','disabled');
	$.post(
		url_modify,
		{
			objs:JSON.encode(objs)
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success == '1'){
				window.location.reload();
			} 
			$('button').attr('disabled','');
		}
	);
} 


/* 保存 */
function fnsubmit(){
	if($('#pic').val() == ''){
		alert('请选择【新增轮播图片】');
		$('#pic').focus();
		return false;
	}
	return true;
}

</script>
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">首页轮播图维护</span>
	</div>
</div>
<div class="blockdiv">
	<div class="titlediv">新增轮播图片</div>
	<form action="" method="post" enctype="multipart/form-data"   onsubmit="return fnsubmit();">
		<div style="margin:5px auto;">
			选择图片：<input type="file" id="pic" name="pic" /> <input type="submit" value="添加" />
		</div>
		<div style="margin:10px auto;color:red">图片大小规格：1280*366   &nbsp;&nbsp;&nbsp;&nbsp;首页将严格按照1280*366进行图片显示</div>
	</form>
</div>	
<hr size="1" style="margin:10px auto" />
<div style="margin:5px auto;color:#666666">
	注意：请点击 上移 或 下移 进行排序，调整顺序之后，请别忘记保存。
</div>
<div> 
	 <table class="tables" >
	 		<thead>
				<tr>
					<th style="width:50px">序号</th>
					<th style="width:150px">轮播图片</th>
					<th style="width:180px">操作</th>
				</tr>
			</thead>
			<tbody id="mytypes">
				<?PHP		
				if(count($rs) > 0 )			
				foreach($rs as $k=>$v){
					echo '
						<tr id="mytype_'.$k.'"   >
							<td class="indexs">'.($k+1).'</td>
							<td>
								<input type="hidden"  id="id_'.$k.'" value="'.$v['id'].'" />
								<img src="'.$themeUrl.$v['pic'].'" width="500" height="144" />
							</td>
							<td class="opts">
								<a href="javascript:void(0)" onclick="fnToUp('.$k.')"><img src="/misc/images/home/totop.gif" /> 上移</a>
								<a href="javascript:void(0)" onclick="fnToDown('.$k.')"><img src="/misc/images/home/tobottom.gif" /> 下移</a>
								<a href="javascript:void(0)" onclick="fnDel('.$k.')"><img src="/misc/images/home/del.gif" /> 删除</a>
							</td>
						</tr> 					
					';
				}
				?> 
			</tbody>
	 </table>
</div>
<div class="button_div">
	<button class=" " onclick="fnSave()">保 存</button>
</div>
 
<!--#include file="../nav/admin_bottom.php" -->